home *** CD-ROM | disk | FTP | other *** search
- unit MidReg2;
- {
- Author : Guy Smith-Ferrier
- Date : February 2000
- Description:
- This unit is a block copy of the TClientDataSetEditor and TCDSDesigner
- classes in Delphi 5's own MidReg.PAS. There have been no changes to this code
- whatsoever. The reason for creating this new unit is simply to change the
- scope of the classes so that they are in the interface section instead of
- in the implementation section. This allows the classes to be inherited from.
- }
-
- interface
-
- uses
- DSDesign, DsgnIntf, DBReg;
-
- type
- TClientDataSetEditor = class(TDataSetEditor)
- private
- FCanCreate: Boolean;
- protected
- function GetDSDesignerClass: TDSDesignerClass; override;
- public
- procedure ExecuteVerb(Index: Integer); override;
- function GetVerb(Index: Integer): string; override;
- function GetVerbCount: Integer; override;
- end;
-
- TCDSDesigner = class(TDSDesigner)
- private
- FPacketRecords: Integer;
- public
- procedure BeginUpdateFieldDefs; override;
- procedure EndUpdateFieldDefs; override;
- function SupportsAggregates: Boolean; override;
- function SupportsInternalCalc: Boolean; override;
- end;
-
- implementation
-
- uses
- DBClient, CDSEdit, DsnDBCst;
-
- procedure TCDSDesigner.BeginUpdateFieldDefs;
- begin
- FPacketRecords := 0;
- if not DataSet.Active then
- begin
- DataSet.FieldDefs.Updated := False;
- FPacketRecords := (DataSet as TClientDataSet).PacketRecords;
- if FPacketRecords <> 0 then
- (DataSet as TClientDataSet).PacketRecords := 0;
- end;
- inherited BeginUpdateFieldDefs;
- end;
-
- procedure TCDSDesigner.EndUpdateFieldDefs;
- begin
- inherited EndUpdateFieldDefs;
- if FPacketRecords <> 0 then
- (DataSet as TClientDataSet).PacketRecords := FPacketRecords;
- end;
-
- function TCDSDesigner.SupportsAggregates: Boolean;
- begin
- Result := True;
- end;
-
- function TCDSDesigner.SupportsInternalCalc: Boolean;
- begin
- Result := True;
- end;
-
- function TClientDataSetEditor.GetDSDesignerClass: TDSDesignerClass;
- begin
- Result := TCDSDesigner;
- end;
-
- procedure TClientDataSetEditor.ExecuteVerb(Index: Integer);
- begin
- if Index <= inherited GetVerbCount - 1 then
- inherited ExecuteVerb(Index) else
- begin
- Dec(Index, inherited GetVerbCount);
- if (Index > 2) and not FCanCreate then Inc(Index);
- case Index of
- 0: begin
- TClientDataSet(Component).FetchParams;
- Designer.Modified;
- end;
- 1: if EditClientDataSet(TClientDataSet(Component), Designer) then
- Designer.Modified;
- 2: if LoadFromFile(TClientDataSet(Component)) then Designer.Modified;
- 3: begin
- TClientDataSet(Component).CreateDataSet;
- Designer.Modified;
- end;
- 4: SaveToFile(TClientDataSet(Component));
- 5: begin
- TClientDataSet(Component).Data := NULL;
- Designer.Modified;
- end;
- end;
- end;
- end;
-
- function TClientDataSetEditor.GetVerb(Index: Integer): string;
- begin
- if Index <= inherited GetVerbCount - 1 then
- Result := inherited GetVerb(Index) else
- begin
- Dec(Index, inherited GetVerbCount);
- if (Index > 2) and not FCanCreate then Inc(Index);
- case Index of
- 0: Result := SFetchParams;
- 1: Result := SClientDSAssignData;
- 2: Result := SLoadFromFile;
- 3: Result := SCreateDataSet;
- 4: Result := SSaveToFile;
- 5: Result := SClientDSClearData;
- end;
- end;
- end;
-
- function TClientDataSetEditor.GetVerbCount: Integer;
- begin
- Result := inherited GetVerbCount + 3;
- FCanCreate := False;
- with TClientDataset(Component) do
- begin
- if Active or (DataSize > 0) then Inc(Result, 2);
- FCanCreate := not Active and ((FieldCount > 0) or (FieldDefs.Count > 0));
- if FCanCreate then Inc(Result, 1);
- end;
- end;
-
- end.
-